use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "dvc_metadata")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i64,
    pub user_id: i64,
    pub dvc_filename: String,
    pub data_filename: String,
    pub data_file_hash: String,
    pub data_file_size: Option<i64>,
    pub dvc_file_path: Option<String>,
    pub dvc_file_hash: Option<String>,
    pub project: Option<String>,
    pub source: String,
    pub created_at: DateTime,
    pub updated_at: DateTime,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(
        belongs_to = "super::users::Entity",
        from = "Column::UserId",
        to = "super::users::Column::Id"
    )]
    User,
    #[sea_orm(has_many = "super::data_items::Entity")]
    DataItems,
}

impl Related<super::users::Entity> for Entity {
    fn to() -> RelationDef {
        Relation::User.def()
    }
}

impl Related<super::data_items::Entity> for Entity {
    fn to() -> RelationDef {
        Relation::DataItems.def()
    }
}

impl ActiveModelBehavior for ActiveModel {}
